module FileListTags
	include Radiant::Taggable

	desc %{
		Cycles thrugh each of the bulletins

		*Usage:*
		<pre><code><r:filelist:each>...</r:filelist:each></code></pre>
	}
	
	tag "filelist" do |tag|

		result = []
		result = "<ul class=\"file_list\">"

		parent_folder = tag.attr['parent_folder']
		folder = tag.attr['folder']
		filetype = tag.attr['filetype']
		limit = tag.attr['limit']
		@files = Dir.glob("/home/stegel_ctb/rails/bh/public/#{parent_folder}/#{folder}/*.#{filetype}").sort {|x,y| y <=> x }

		#	for file in @files
		Integer(limit).times do |i|
			file = @files[i]
			file_name = File.basename(file)
			split_name = file_name.split("_")
			
			file_date =  split_name[1].split(".")
			file_date = Date.parse(file_date[0])
			formatted_date = file_date.strftime("%b %d, %Y")
			
			result << "<li><a href=\"/#{parent_folder}/#{folder}/#{file_name}\">#{formatted_date}</a></li>"			
			
		end

		result << "</ul>"

		result

	end
end
		
